package com.tsvetanv.data.binding.nested.properties;

import junit.framework.TestCase;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.tsvetanv.data.binding.model.nested.NestedCommandBean;

public class NestedCommandBeanTest extends TestCase {
	private NestedCommandBean bean;
	private ServletRequestDataBinder binder;
	private MockHttpServletRequest request;

	/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
	@Override
	protected void setUp() throws Exception {
		bean = new NestedCommandBean();
		binder = new ServletRequestDataBinder(bean, "beanName");
		request = new MockHttpServletRequest();
	}

	public void testNestedCommandBind() {
		request.addParameter("name.firstName", "Tsvetan");
		request.addParameter("name.lastName", "Vasilev");

		binder.bind(request);

		assertEquals("Tsvetan", bean.getName().getFirstName());
		assertEquals("Vasilev", bean.getName().getLastName());

	}
}
